package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.sc.nft.entity.BuyFirstCollection;
import com.sc.nft.entity.vo.RelatedCollectionsListVO;
import com.sc.nft.mapper.BuyFirstCollectionMapper;
import lombok.extern.slf4j.Slf4j;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * (sc_buy_first_collection)数据DAO
 *
 * @author rdg
 * @since 2022-08-03 15:22:31
 * @description 由 Mybatisplus Code Generator 创建
 */
@Slf4j
@Repository
public class BuyFirstCollectionDao extends ServiceImpl<BuyFirstCollectionMapper, BuyFirstCollection> {

    public List<RelatedCollectionsListVO> relatedCollectionsList(Long id) {
        return baseMapper.relatedCollectionsList(id);
    }

    //同样的商品同样的藏品应该是只有一个绑定记录。有多个会有问题
    public BuyFirstCollection selectByProductIdAndCollectionId(Long productId, Long collectionId) {
        LambdaQueryWrapper<BuyFirstCollection>wrapper=new LambdaQueryWrapper<>();
        wrapper.eq(BuyFirstCollection::getProductId,productId);
        wrapper.eq(BuyFirstCollection::getCollectionBuyFirstId,collectionId);
        wrapper.last("limit 1");
        return getOne(wrapper);
    }


    public List<BuyFirstCollection> selectByProductId(Long productId) {
        LambdaQueryWrapper<BuyFirstCollection>wrapper=new LambdaQueryWrapper<>();
        wrapper.eq(BuyFirstCollection::getProductId,productId);
        return list(wrapper);
    }

    public Boolean getIsExistByProductId(Long productId) {
        LambdaQueryWrapper<BuyFirstCollection> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(BuyFirstCollection::getProductId, productId);
        return count(wrapper) > 0;
    }
}